<?php 
defined('RUN_KATANA') or die('Restricted access');
?>
<table class="com_form" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr><td>
<?php 
if($shop->CurrentOrder)
{
	if($shop->CurrentOrder->getId() > 0)
	{
		$order = $shop->CurrentOrder;
		if(file_exists(ORDERS_PATH.'order_'.$shop->CurrentOrder->getId().'_confirmation.html'))
		{ require_once(ORDERS_PATH.'order_'.$shop->CurrentOrder->getId().'_confirmation.html'); }
		else
		{ echo $shop->CurrentOrder->sendOrderConfirmation(); }
		if($shop->CurrentOrder->getConfirmed() == 1)
		{ $cart->clearCart($user); }
		
		$adc->setCurrentAdId($shop->CurrentOrder->getAdId());
		if(is_object($adc->getCurrentAd()))
		{
			if($adc->CurrentAd->getOrderId() == 0)
			{ 
				$adc->CurrentAd->setOrderId($shop->CurrentOrder->getId()); 
				$adc->CurrentAd->setDataChanged(true);
			}
			if($adc->CurrentAd->getDatePaid() == '0000-00-00 00:00:00')
			{ 
				$adc->CurrentAd->setDatePaid(date('y-m-d H:i:s')); 
				$adc->CurrentAd->setDataChanged(true);
			}
			if($adc->CurrentAd->getAdQuotas() > 0)
			{
				$credits = 0;
				$credits = $user->getCreditsBought() + $adc->CurrentAd->getAdQuotas();
				$user->setCreditsBought($credits);
				$user->saveUser();
			}
			$adc->CurrentAd->Update();
			$adc->CurrentAd->Publish();
			/*
			$com->setButtonsContent(array 
			(
				0 => array 
				(	
					'title' => ucfirst($txt->getWord('activate').' '.$txt->getWord('ad').'&nbsp;&gt;&gt;'),
					'href' => '/c/'.$com->getComId().'?list=ad&activate='.$adc->getCurrentAd()->getId(),
					'onclick' => '',
				)
			));
			*/
		}
		?>
        <br /><br />
        <p><a target="_blank" href="<?php echo $katana->getFormAction(); ?>&orderid=<?php echo $shop->CurrentOrder->getId(); ?>&action=<?php echo $_REQUEST['action'] ?>&print=1">Utskriftsvennlig versjon</a></p>
        <p>Vi har sendt deg en epost</p><br />
        <?php echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?>
        <?php if($katana->getAnalyticsID() != ''): ?>
		<script type="text/javascript">
		<?php 
		if(UNIVERSAL_ANALYTICS)
		{
			?>
			ga('ecommerce:addTransaction', { 'id': '<?php echo $order->getId(); ?>', 'affiliation': '<?php echo $katana->getCompanyName(); ?>',  'revenue': '<?php echo number_format($order->getCostItemsTotal(1),2,'.',' '); ?>', 'shipping': '<?php echo number_format($order->getCostShipping(2),2,'.',' ') ?>', 'tax': '<?php echo number_format($order->getCostItemsVat(2),2,'.',' ');  ?>' });
			<?php
			if(count($order->OrderItems) > 0)
			{
				foreach($order->OrderItems as $item)
				{
					?>
					ga('ecommerce:addItem', { 'id': '<?php echo $order->getId(); ?>', 'name': '<?php echo $txt->formatText($item->getItemTitle()); ?>', 'sku': '<?php echo $item->getItemIdentity(); ?>', 'category': '<?php echo $item->getItemVarTitle(); ?>', 'price': '<?php echo number_format($item->getSingleItemPriceTotal(1),2,'.',' '); ?>', 'quantity': '<?php echo $item->getCount(); ?>' });
					<?php
				}
			}
			?>
			ga('ecommerce:send');
			<?php
		}
		else
		{
			?>
			var _gaq = _gaq || [];
			_gaq.push(['_setAccount', '<?php echo $katana->getAnalyticsID(); ?>']);
			//_gaq.push(['_trackPageview']);
			_gaq.push(['_addTrans',
			'<?php echo $shop->CurrentOrder->getId(); ?>',           // order ID - required
			'<?php echo $katana->getCompanyName(); ?>',  // affiliation or store name
			'<?php echo number_format($shop->CurrentOrder->getCostItemsTotal(1),2,'.',' '); ?>',          //11.99 total - required
			'<?php echo number_format($shop->CurrentOrder->getCostItemsVat(2),2,'.',' ');  ?>',           //1.29 tax
			'<?php echo number_format($shop->CurrentOrder->getCostShipping(2),2,'.',' ') ?>',              //5 shipping
			'<?php echo $shop->CurrentOrder->getBillingCity();  ?>',       //San Jose city
			'',     // state or province
			'<?php echo $shop->CurrentOrder->getBillingCountry();  ?>'             // country
			]);
			<?php 
			if(count($shop->CurrentOrder->OrderItems) > 0)
			{
				foreach($shop->CurrentOrder->OrderItems as $item)
				{
					?>
					// add item might be called for every item in the shopping cart
					// where your ecommerce engine loops through each item in the cart and
					// prints out _addItem for each
					_gaq.push(['_addItem',
						'<?php echo $shop->CurrentOrder->getId(); ?>',           //1234 order ID - required
						'<?php echo $item->getItemIdentity(); ?>',           //DD44 SKU/code - required
						'<?php echo $txt->formatText($item->getItemTitle()); ?>',        //T-Shirt product name
						'<?php echo $item->getItemVarTitle(); ?>',   //Green Medium category or variation
						'<?php echo number_format($item->getSingleItemPriceTotal(1),2,'.',' '); ?>',          //11.99 unit price - required
						'<?php echo $item->getCount(); ?>'               //1 quantity - required
					]);
					<?
				}
			}
			?>
			 _gaq.push(['_trackTrans']); //submits transaction to the Analytics servers
			<?php
		}
		?>
		</script>
        <?php endif; ?>
		<?php
	}
}
?></td>
</tr>
</table>